package com.celan.year2023.month05.day02;

/**
 * @author Celan
 * @ClassName Solution02
 * @description: TODO
 * @date 2023/05/02
 * @version: 1.0
 */
public class Solution02 {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = 0;
        int min = n + 1;
        int sum = 0;
        while (right < n) {
            sum += nums[right];
            if (sum >= target) {
                while (sum >= target) {
                    min = Math.min(min, right - left + 1);
                    sum -= nums[left++];
                }
            }
            right++;
        }
        return min == n + 1 ? 0 : min;
    }

    public static void main(String[] args) {
        Solution02 solution02 = new Solution02();
        int i = solution02.minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3});
        System.out.println(i);
    }
}
